<template>
  <div class="app-container">
    <el-row :gutter="20">

      <el-col :span="8" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>基本信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li :style="{
                display: key === 'govUserbrief' && 'block'
              }" class="list-group-item self" v-for="({ label, value, icon, key }, index) in infoSchema" :key="index">
                <div class="self_icon"><svg-icon :icon-class="icon" style="margin-right:5px" />{{ label }}</div>
                <div :style="key === 'govUserbrief' && 'margin-top:11px;text-align:left'" class="self_content">{{ value }}
                </div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>

      <el-col :span="16" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>信息修改</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="comDetail" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";
import { getComhome } from "@/api/truth/comhome";



export default {
  name: "comzhuye",
  dicts: ['sys_gov_role'],
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      currentUserId: 1,
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      comDetail: {},
      infoSchema: [
        {
          label: '企业名称',
          icon: 'user',
          key: 'comUsername',
          value: ''
        }, {
          label: '联系方式',
          icon: 'phone',
          key: 'comUsertele',
          value: ''
        }, {
          label: '邮箱地址',
          icon: 'email',
          key: 'comUsermail',
          value: ''
        }, {
          label: '联系地址',
          icon: 'dizhi',
          key: 'comUseraddr',
          value: ''
        },
        {
          label: '企业简介',
          icon: 'jianjie',
          key: 'comUserbrief',
          value: ''
        }, {
          label: '创建日期',
          icon: 'date',
          key: 'createTime',
          value: ''
        },
      ]
    };

  },
  created() {
    this.getList();
  },
  methods: {
    getUser() {
      return new Promise((resolve, reject) => {
        getUserProfile().then(response => {
          this.user = response.data;
          this.roleGroup = response.roleGroup;
          this.postGroup = response.postGroup;
          resolve(response)
        });

      })

    },
    getList(info) {
      this.loading = true;
      getComhome(this.currentUserId).then(response => {
        this.comDetail = response.data
        this.comhomeList = response.rows;
        this.total = response.total;
        this.loading = false;
        const finDetial = { ...response.data };
        this.infoSchema.map((item) => {
          item.value = finDetial[item.key]
        })
      });
    }

  }
};
</script>
<style lang="scss" scoped>
li {
  border-bottom: 1px solid #e7eaec
}

.self {

  display: flex;

  div {}

  .self_icon {
    width: 30%;
    min-width: 90px;
  }

  .self_content {
    text-align: right;
    flex: 1;
  }
}
</style>
